package com.guigu.dispatch.handler;
import com.guigu.tms.exception.TmsException;
import com.guigu.tms.result.R;
import com.guigu.tms.result.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName:ExceptionHandler
 * @Description://TODO
 * @Author:taoLong
 * @Date:2021/10/26:9:28 星期二
 * @email:2391611102@qq.com or 2391611102qq@gmail.com
 */
@RestControllerAdvice
@Api(tags = "全局异常处理器")
public class GlobalExceptionHandler {

    @ExceptionHandler(value = TmsException.class)
    @ApiOperation("返回异常消息")
    @ApiImplicitParam(name = "e", value = "自定义异常消息对象", required = true, dataType = "Exception")
    public R error(TmsException e) {
        return new R(e.getCode(), e.getMessage(), false, null);
    }


    // @ExceptionHandler(value = Exception.class)
    @ApiOperation("全局异常消息处理")
    @ApiImplicitParam(name = "e", value = "全局异常消息", dataTypeClass = Exception.class)
    public R globalException(Exception e) {
        System.out.println(e.getMessage());
        return new R(ResultCode.ERROR_CODE, "执行了全局异常处理", false);
    }
}
